﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Worktool.CODE_Chris.SQL_DATA;

namespace Worktool.CODE_Chris.DataSourceHelpers
{
    public class CommissioningHelper
    {
        private Commissioning parent;
        private GeneralHelper helper;
        private SQL sql;

        private DataGridView gridView1, gridView2, gridView3, gridView4;

        private SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter();
        private SqlDataAdapter sqlDataAdapter2 = new SqlDataAdapter();
        private SqlDataAdapter sqlDataAdapter3 = new SqlDataAdapter();
        private SqlDataAdapter sqlDataAdapter3a = new SqlDataAdapter();
        private SqlDataAdapter sqlDataAdapter4 = new SqlDataAdapter();

        private BindingSource bindingSource1 = new BindingSource();
        private BindingSource bindingSource2 = new BindingSource();
        private BindingSource bindingSource3 = new BindingSource();
        private BindingSource bindingSource4 = new BindingSource();

        private DataTable dataTable1, dataTable2, dataTable3, dataTable4;

        private String select1, select2, select3, select4;
        private String update1, update2, update3, update3a, update4;

        private int columnNr = 0;

        private Boolean isPaste = false;
        private int countPasteError = 0;

        public CommissioningHelper(DataGridView gridView1,DataGridView gridView2,DataGridView gridView3, DataGridView gridView4, Commissioning parent)
        {
            this.parent = parent;
            this.gridView1 = gridView1;
            this.gridView2 = gridView2;
            this.gridView3 = gridView3;
            this.gridView4 = gridView4;
            init();
        }

        private void init()
        {
            sql = new SQL();
            helper = new GeneralHelper();

            populateSQLStrings();
        }

        #region Methoden für gridView1 (SerialNumbers)
        public void getData1()
        {
            try
            {
                gridView1.DataSource = bindingSource1;

                sqlDataAdapter1 = new SqlDataAdapter(select1, Login.connection);

                SqlCommandBuilder commandBuilder = new SqlCommandBuilder(sqlDataAdapter1);

                // Populate a new data table and bind it to the BindingSource.
                dataTable1 = new DataTable();
                dataTable1.Locale = System.Globalization.CultureInfo.InvariantCulture;
                sqlDataAdapter1.Fill(dataTable1);
                bindingSource1.DataSource = dataTable1;

                gridView1.AutoGenerateColumns = false;

                //Zellennachbearbeitung
                setHiddenColumns1();
                setDisabledColumns1();

                //Eventhandler setzen
                gridView1.CellFormatting -= new DataGridViewCellFormattingEventHandler(this.gridView1_CellFormatting);

                gridView1.CellFormatting += new DataGridViewCellFormattingEventHandler(this.gridView1_CellFormatting);
            }
            catch (Exception e)
            {
                sql.log("FEHLER", e, this.ToString() + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }

        private void gridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.ColumnIndex != -1)
            {
                DataGridViewColumn col = gridView1.Columns[e.ColumnIndex];

                //Blaue Zellen
                if (col.Name == "Manufacturer" && col.DefaultCellStyle.BackColor != helper.getColors()[0]) col.DefaultCellStyle.BackColor = helper.getColors()[0];
                if (col.Name == "Model" && col.DefaultCellStyle.BackColor != helper.getColors()[0]) col.DefaultCellStyle.BackColor = helper.getColors()[0];
                if (col.Name == "serialNumber" && col.DefaultCellStyle.BackColor != helper.getColors()[0]) col.DefaultCellStyle.BackColor = helper.getColors()[0];
            }
        }

        private void setHiddenColumns1()
        {
            try
            {
                gridView1.Columns["id"].Visible = false;
                gridView1.Columns["marriageDate"].Visible = false;
                gridView1.Columns["marriedToArtikelId"].Visible = false;
                gridView1.Columns["marriageUser"].Visible = false;
            }
            catch (Exception e)
            {

            }
        }

        private void setDisabledColumns1()
        {
            try
            {
                gridView1.Columns["Manufacturer"].ReadOnly = true;
                gridView1.Columns["Model"].ReadOnly = true;
                gridView1.Columns["serialNumber"].ReadOnly = true;
                gridView1.Columns["id"].ReadOnly = true;
                gridView1.Columns["marriageDate"].ReadOnly = true;
                gridView1.Columns["marriedToArtikelId"].ReadOnly = true;
                gridView1.Columns["marriageUser"].ReadOnly = true;
            }
            catch (Exception e)
            {

            }
        }

        public DataTable getTable1()
        {
            return dataTable1;
        }
        #endregion

        #region Methoden für gridView2 (Bulk)
        public void getData2()
        {
            try
            {
                gridView2.DataSource = bindingSource2;

                sqlDataAdapter2 = new SqlDataAdapter(select2, Login.connection);

                SqlCommandBuilder commandBuilder = new SqlCommandBuilder(sqlDataAdapter2);

                // Populate a new data table and bind it to the BindingSource.
                dataTable2 = new DataTable();
                dataTable2.Locale = System.Globalization.CultureInfo.InvariantCulture;
                sqlDataAdapter2.Fill(dataTable2);
                bindingSource2.DataSource = dataTable2;

                gridView2.AutoGenerateColumns = false;

                //Zellennachbearbeitung
                setHiddenColumns2();
                setDisabledColumns2();

                //Eventhandler setzen
                gridView2.CellFormatting -= new DataGridViewCellFormattingEventHandler(this.gridView2_CellFormatting);

                gridView2.CellFormatting += new DataGridViewCellFormattingEventHandler(this.gridView2_CellFormatting);
            }
            catch (Exception e)
            {
                sql.log("FEHLER", e, this.ToString() + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }

        private void gridView2_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.ColumnIndex != -1)
            {
                DataGridViewColumn col = gridView2.Columns[e.ColumnIndex];

                //Blaue Zellen
                if (col.Name == "Manufacturer" && col.DefaultCellStyle.BackColor != helper.getColors()[0]) col.DefaultCellStyle.BackColor = helper.getColors()[0];
                if (col.Name == "Model" && col.DefaultCellStyle.BackColor != helper.getColors()[0]) col.DefaultCellStyle.BackColor = helper.getColors()[0];
                if (col.Name == "ID" && col.DefaultCellStyle.BackColor != helper.getColors()[0]) col.DefaultCellStyle.BackColor = helper.getColors()[0];
            }
        }

        private void setHiddenColumns2()
        {
            try
            {
                gridView2.Columns["serialNumber"].Visible = false;
                gridView2.Columns["isBulk"].Visible = false;
            }
            catch (Exception e)
            {

            }
        }

        private void setDisabledColumns2()
        {
            try
            {
                gridView2.Columns["ID"].ReadOnly = true;
                gridView2.Columns["Manufacturer"].ReadOnly = true;
                gridView2.Columns["Model"].ReadOnly = true;
                gridView2.Columns["serialNumber"].ReadOnly = true;
                gridView2.Columns["isBulk"].ReadOnly = true;
            }
            catch (Exception e)
            {

            }
        }

        public DataTable getTable2()
        {
            return dataTable2;
        }
        #endregion

        #region Methoden für gridView3 (Material in Venue)
        public void getData3()
        {
            try
            {
                gridView3.DataSource = bindingSource3;

                //DataAdapter für Seriennummer*************************
                sqlDataAdapter3 = new SqlDataAdapter(select3, Login.connection);
                sqlDataAdapter3.UpdateCommand = new SqlCommand(update3, new SqlConnection(Login.connection));

                //Neu zu schreibende Parameter
                sqlDataAdapter3.UpdateCommand.Parameters.Add("@Seriennummer", SqlDbType.NVarChar, 50, "Seriennummer");

                //Daten aus der Originalquelle
                SqlParameter parameter = sqlDataAdapter3.UpdateCommand.Parameters.Add("@Original_ID", SqlDbType.Int, 50, "ID");
                parameter.SourceVersion = DataRowVersion.Original;
                parameter = sqlDataAdapter3.UpdateCommand.Parameters.Add("@Original_Seriennummer", SqlDbType.NVarChar, 50, "Seriennummer");
                parameter.SourceVersion = DataRowVersion.Original;

                //Check auf Null-Werte
                parameter = sqlDataAdapter3.UpdateCommand.Parameters.Add("@IsNull_Seriennummer", SqlDbType.Int, 50, "Seriennummer");
                parameter.SourceVersion = DataRowVersion.Original;
                parameter.SourceColumnNullMapping = true;

                SqlCommandBuilder commandBuilder = new SqlCommandBuilder(sqlDataAdapter3);

                //DataAdapter für Packstück*************************
                sqlDataAdapter3a = new SqlDataAdapter(select3, Login.connection);
                sqlDataAdapter3a.UpdateCommand = new SqlCommand(update3a, new SqlConnection(Login.connection));

                //Neu zu schreibende Parameter
                sqlDataAdapter3a.UpdateCommand.Parameters.Add("@packstueck", SqlDbType.NVarChar, 50, "Packstück Nr.");

                //Daten aus der Originalquelle
                parameter = sqlDataAdapter3a.UpdateCommand.Parameters.Add("@Original_IDMaterialExtended", SqlDbType.Int, 50, "IDMaterialExtended");
                parameter.SourceVersion = DataRowVersion.Original;
                parameter = sqlDataAdapter3a.UpdateCommand.Parameters.Add("@Original_packstueck", SqlDbType.NVarChar, 50, "Packstück Nr.");
                parameter.SourceVersion = DataRowVersion.Original;

                //Check auf Null-Werte
                parameter = sqlDataAdapter3a.UpdateCommand.Parameters.Add("@IsNull_packstueck", SqlDbType.Int, 50, "Packstück Nr.");
                parameter.SourceVersion = DataRowVersion.Original;
                parameter.SourceColumnNullMapping = true;

                SqlCommandBuilder commandBuildera = new SqlCommandBuilder(sqlDataAdapter3a);

                // Populate a new data table and bind it to the BindingSource.
                dataTable3 = new DataTable();
                dataTable3.Locale = System.Globalization.CultureInfo.InvariantCulture;
                sqlDataAdapter3.Fill(dataTable3);
                bindingSource3.DataSource = dataTable3;

                gridView3.AutoGenerateColumns = false;

                //Zellennachbearbeitung
                setHiddenColumns3();
                setDisabledColumns3();

                //Eventhandler setzen
                gridView3.CellFormatting -= new DataGridViewCellFormattingEventHandler(this.gridView3_CellFormatting);
                gridView3.CellEndEdit -= new DataGridViewCellEventHandler(this.gridView3_CellEndEdit);
                gridView3.CellMouseClick -= new DataGridViewCellMouseEventHandler(this.gridView3_CellMouseClick);
                gridView3.CellMouseDown -= new DataGridViewCellMouseEventHandler(this.gridView3_CellMouseDown);

                gridView3.CellFormatting += new DataGridViewCellFormattingEventHandler(this.gridView3_CellFormatting);
                gridView3.CellEndEdit += new DataGridViewCellEventHandler(this.gridView3_CellEndEdit);
                gridView3.CellMouseClick += new DataGridViewCellMouseEventHandler(this.gridView3_CellMouseClick);
                gridView3.CellMouseDown += new DataGridViewCellMouseEventHandler(this.gridView3_CellMouseDown);
            }
            catch (Exception e)
            {
                sql.log("FEHLER", e, this.ToString() + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }

        private void gridView3_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (e.RowIndex != -1 && e.ColumnIndex != -1)
                {
                    gridView3.CurrentCell = gridView3.Rows[e.RowIndex].Cells[e.ColumnIndex];
                }
                else
                {
                    gridView3.ClearSelection();
                }
            }
        }

        private void gridView3_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                ContextMenu m = new ContextMenu();

                MenuItem copy = new MenuItem("Copy");
                copy.Click += new System.EventHandler(this.copy3_Click);
                m.MenuItems.Add(copy);

                MenuItem paste = new MenuItem("Paste");
                paste.Click += new System.EventHandler(this.paste3_Click);
                m.MenuItems.Add(paste);

                MenuItem delete = new MenuItem("Delete");
                delete.Click += new System.EventHandler(this.delete3_Click);
                m.MenuItems.Add(delete);

                var relativeMousePosition = gridView3.PointToClient(Cursor.Position);
                m.Show(gridView3, relativeMousePosition);
            }
        }

        private void copy3_Click(object sender, EventArgs e)
        {
            try
            {
                if (gridView3.SelectedCells.Count == 1 && gridView3.SelectedCells[0].Value.ToString() != "")
                {
                    Clipboard.SetText(gridView3.SelectedCells[0].Value.ToString());
                }
                else if (gridView3.SelectedCells.Count == 1)
                {
                    if (gridView3.SelectedCells[0].OwningColumn.CellType == typeof(DataGridViewComboBoxCell))
                    {
                        if (gridView3.SelectedCells[0].Value.ToString() != "")
                        {
                            Clipboard.SetText(gridView3.SelectedCells[0].Value.ToString());
                        }
                        else
                        {
                            Clipboard.Clear();
                        }
                    }
                    else
                    {
                        Clipboard.Clear();
                    }
                }
                else
                {
                    Clipboard.Clear();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Copy to Clipboard war nicht erfolgreich. Bitte versuchen Sie es erneut.", "Fehler");
            }
        }

        private void paste3_Click(object sender, EventArgs e)
        {
            //Für Korrekte Behandlung der DBConcurrencyException
            isPaste = true;

            List<int> pasteZeilen = new List<int> { };
            string pasteColumn = "";
            if (gridView3.SelectedCells.Count != 0) pasteColumn = gridView3.SelectedCells[0].OwningColumn.Name;

            for (int i = 0; i < gridView3.SelectedCells.Count; i++)
            {
                pasteZeilen.Add(gridView3.SelectedCells[i].OwningRow.Index);
            }

            if (Clipboard.GetText() != "")
            {
                for (int i = 0; i < pasteZeilen.Count; i++)
                {
                    if (!gridView3.SelectedCells[i].OwningColumn.ReadOnly)
                    {
                        try
                        {
                            gridView3.Rows[pasteZeilen[i]].Cells[pasteColumn].Value = Clipboard.GetText();

                            // Zeile zurück in die DB schreiben
                            if (gridView3.SelectedCells[i].OwningColumn.Name == "Seriennummer") 
                            {
                                columnNr = -2;
                            }
                            else if (gridView3.SelectedCells[i].OwningColumn.Name == "Packstück Nr.")
                            {
                                columnNr = -1;
                            }
                            else
                            {
                                columnNr = 0;
                            }

                            gridView3_CellEndEdit(null, null);
                        }
                        catch (Exception ex)
                        {

                        }
                    }
                }
                if (countPasteError > 0)
                {
                    if (MessageBox.Show("Der Datensatz wurde in der Zwischenzeit auf dem Server bearbeitet. Es wurden nur die Datensätze aktualisiert, die nicht im Hintergrund bearbeitet wurden. Alle Datensätze werden nun neu geladen.", "Fehler", MessageBoxButtons.OK) == DialogResult.OK)
                    {
                        parent.reloadAllData();
                    }
                }
            }
            countPasteError = 0;
            isPaste = false;
        }

        private void delete3_Click(object sender, EventArgs e)
        {
            //Für Korrekte Behandlung der DBConcurrencyException
            isPaste = true;

            List<int> deleteZeilen = new List<int> { };
            string deleteColumn = "";
            if (gridView3.SelectedCells.Count != 0) deleteColumn = gridView3.SelectedCells[0].OwningColumn.Name;

            for (int i = 0; i < gridView3.SelectedCells.Count; i++)
            {
                deleteZeilen.Add(gridView3.SelectedCells[i].OwningRow.Index);
            }

            if (gridView3.SelectedCells.Count != 0)
            {
                for (int i = 0; i < gridView3.SelectedCells.Count; i++)
                {
                    if (!gridView3.SelectedCells[i].OwningColumn.ReadOnly)
                    {
                        try
                        {
                            if (gridView3.SelectedCells[i].ValueType == typeof(System.DateTime)) gridView3.SelectedCells[i].Value = DBNull.Value;
                            if (gridView3.SelectedCells[i].ValueType == typeof(int)) gridView3.SelectedCells[i].Value = 0;
                            if (gridView3.SelectedCells[i].ValueType == typeof(string)) gridView3.SelectedCells[i].Value = String.Empty;
                            if (gridView3.SelectedCells[i].ValueType == typeof(Boolean)) gridView3.SelectedCells[i].Value = Boolean.FalseString;

                            if (gridView3.SelectedCells[i].ValueType == typeof(System.DateTime) || gridView3.SelectedCells[i].ValueType == typeof(int) || gridView3.SelectedCells[i].ValueType == typeof(string) || gridView3.SelectedCells[i].ValueType == typeof(Boolean))
                            {
                                if (gridView3.SelectedCells[i].OwningColumn.Name == "Seriennummer")
                                {
                                    columnNr = -2;
                                }
                                else if (gridView3.SelectedCells[i].OwningColumn.Name == "Packstück Nr.")
                                {
                                    columnNr = -1;
                                }
                                else
                                {
                                    columnNr = 0;
                                }

                                // Zeile zurück in die DB schreiben
                                gridView3_CellEndEdit(null, null);
                            }
                        }
                        catch (Exception ex)
                        {

                        }
                    }
                }

                if (countPasteError > 0)
                {
                    if (MessageBox.Show("Der Datensatz wurde in der Zwischenzeit auf dem Server bearbeitet. Es wurden nur die Datensätze aktualisiert, die nicht im Hintergrund bearbeitet wurden. Alle Datensätze werden nun neu geladen.", "Fehler", MessageBoxButtons.OK) == DialogResult.OK)
                    {
                        parent.reloadAllData();
                    }
                }
            }

            countPasteError = 0;
            isPaste = false;
        }

        public void gridView3_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            //Hier werden die Daten der editierten Zelle wieder in die Datenbank geschrieben
            gridView3.BindingContext[gridView3.DataSource].EndCurrentEdit();

            if (e == null) updateGridView3(-1,columnNr); else updateGridView3(e.RowIndex,e.ColumnIndex);
        }

        public Boolean updateGridView3(int row, int column)
        {
            try
            {
                if (column >= 0)
                {
                    if (gridView3.Columns[column].Name == "Seriennummer")
                    {
                        //Update Seriennummer
                        sqlDataAdapter3.Update(dataTable3);

                        parent.updateListeSerialPositionen();
                    }
                    else if (gridView3.Columns[column].Name == "Packstück Nr.")
                    {
                        //Update Packstück
                        sqlDataAdapter3a.Update(dataTable3);
                    }
                }
                else
                {
                    if (column == -1)
                    {
                        //Setzen des Packstücks aus dem Code heraus
                        sqlDataAdapter3a.Update(dataTable3);
                    }
                    else if (column == -2)
                    {
                        //Update Seriennummer
                        sqlDataAdapter3.Update(dataTable3);

                        parent.updateListeSerialPositionen();
                    }

                }
                
                return true;
            }
            catch (DBConcurrencyException e)
            {
                if (isPaste)
                {
                    countPasteError++;
                }
                else
                {
                    if (column != -1)
                    {
                        if (MessageBox.Show("Der Datensatz wurde in der Zwischenzeit auf dem Server bearbeitet. Die Datensätze werden neu geladen.", "Fehler", MessageBoxButtons.OK) == DialogResult.OK)
                        {
                            parent.reloadAllData();
                        }
                    }
                }

                sql.log("FEHLER", e, this.ToString() + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name);
                return false;
            }
        }

        private void gridView3_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.ColumnIndex != -1)
            {
                DataGridViewColumn col = gridView3.Columns[e.ColumnIndex];

                //Blaue Zellen
                if (col.Name == "Venue" && col.DefaultCellStyle.BackColor != helper.getColors()[0]) col.DefaultCellStyle.BackColor = helper.getColors()[0];
                if (col.Name == "Manufacturer" && col.DefaultCellStyle.BackColor != helper.getColors()[0]) col.DefaultCellStyle.BackColor = helper.getColors()[0];
                if (col.Name == "Model" && col.DefaultCellStyle.BackColor != helper.getColors()[0]) col.DefaultCellStyle.BackColor = helper.getColors()[0];
                if (col.Name == "JLM" && col.DefaultCellStyle.BackColor != helper.getColors()[0]) col.DefaultCellStyle.BackColor = helper.getColors()[0];
                if (col.Name == "Positions_ID" && col.DefaultCellStyle.BackColor != helper.getColors()[0]) col.DefaultCellStyle.BackColor = helper.getColors()[0];
                if (col.Name == "Technische_Ausprägung_1" && col.DefaultCellStyle.BackColor != helper.getColors()[0]) col.DefaultCellStyle.BackColor = helper.getColors()[0];
                if (col.Name == "Technische_Ausprägung_2" && col.DefaultCellStyle.BackColor != helper.getColors()[0]) col.DefaultCellStyle.BackColor = helper.getColors()[0];
                if (col.Name == "Technische_Ausprägung_3" && col.DefaultCellStyle.BackColor != helper.getColors()[0]) col.DefaultCellStyle.BackColor = helper.getColors()[0];
                if (col.Name == "Virtuelle Pack Nr." && col.DefaultCellStyle.BackColor != helper.getColors()[0]) col.DefaultCellStyle.BackColor = helper.getColors()[0];
            }
        }

        private void setHiddenColumns3()
        {
            try
            {
                gridView3.Columns["Description"].Visible = false;
                gridView3.Columns["Bestellausprägung_1"].Visible = false;
                gridView3.Columns["Bestellausprägung_2"].Visible = false;
                gridView3.Columns["Liefertermin"].Visible = false;
                gridView3.Columns["Farbe"].Visible = false;
                gridView3.Columns["Bedarfstermin"].Visible = false;
                gridView3.Columns["ID"].Visible = false;
                gridView3.Columns["IDMaterialExtended"].Visible = false;
                gridView3.Columns["Fitting-No"].Visible = false;
            }
            catch (Exception e)
            {

            }
        }

        private void setDisabledColumns3()
        {
            try
            {
                gridView3.Columns["Venue"].ReadOnly = true;
                gridView3.Columns["Manufacturer"].ReadOnly = true;
                gridView3.Columns["Model"].ReadOnly = true;
                gridView3.Columns["JLM"].ReadOnly = true;
                gridView3.Columns["Positions_ID"].ReadOnly = true;
                gridView3.Columns["Technische_Ausprägung_1"].ReadOnly = true;
                gridView3.Columns["Technische_Ausprägung_2"].ReadOnly = true;
                gridView3.Columns["Technische_Ausprägung_3"].ReadOnly = true;
                gridView3.Columns["Virtuelle Pack nr."].ReadOnly = true;
            }
            catch (Exception e)
            {

            }
        }

        public DataTable getTable3()
        {
            return dataTable3;
        }
        #endregion

        #region Methoden für gridView4 (Log)
        public void getData4()
        {
            try
            {
                gridView4.DataSource = bindingSource4;

                sqlDataAdapter4 = new SqlDataAdapter(select4, Login.connection);

                SqlCommandBuilder commandBuilder = new SqlCommandBuilder(sqlDataAdapter4);

                // Populate a new data table and bind it to the BindingSource.
                dataTable4 = new DataTable();
                dataTable4.Locale = System.Globalization.CultureInfo.InvariantCulture;
                sqlDataAdapter4.Fill(dataTable4);
                bindingSource4.DataSource = dataTable4;

                gridView4.AutoGenerateColumns = false;
            }
            catch (Exception e)
            {
                sql.log("FEHLER", e, this.ToString() + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }

        public DataTable getTable4()
        {
            return dataTable4;
        }
        #endregion

        #region SQL-Befehle als Strings
        private void populateSQLStrings()
        {
            select1 = "SELECT id, Manufacturer, Model, serialNumber, marriageDate, marriedToArtikelId, marriageUser FROM vw_comm_Serials";
            update1 = "";

            select2 = "SELECT ID, Manufacturer, Model, serialNumber, isBulk FROM vw_comm_materialTotal";
            update2 = "";

            select3 = "SELECT Venue, Manufacturer, Model, JLM, Positions_ID, Seriennummer, packstueck AS [Packstück Nr.], Technische_Ausprägung_1, Technische_Ausprägung_2, Technische_Ausprägung_3, Description, Bestellausprägung_1, Bestellausprägung_2, Liefertermin, Farbe, Bedarfstermin,  ID,  IDMaterialExtended, [Virtuelle Pack Nr.], [Fitting-No] FROM vw_eng_MaterialDetail";
            update3 = "UPDATE TOTAL_materialDetail SET Seriennummer = @Seriennummer WHERE (ID = @Original_ID) AND (@IsNull_Seriennummer = 1 AND Seriennummer IS NULL OR Seriennummer = @Original_Seriennummer)";
            update3a = "UPDATE tbl_materialDetailExtended SET packstueck = @packstueck WHERE (ID = @Original_IDMaterialExtended) AND (@IsNull_packstueck = 1 AND packstueck IS NULL OR packstueck = @Original_packstueck)";

            select4 = "";
            update4 = "";
        }
        #endregion

        public void setColumnNr(int nr)
        {
            columnNr = nr;
        }

    }
}
